﻿using System;
using System.ComponentModel;
using System.Xml;
using Moonlite.Data.EditorInterop.Internal;

namespace Moonlite.Data.EditorInterop
{
    [DefaultProperty("Id")]
    [DisplayName("Type")]
    public class ObjectDoodad : ObjectUnit
    {
        public const int DoodadOwnerPlayer = 1000;

        internal static new IDeserializedObject Parse(XmlNode node)
        {
            int id = 0;
            float[] position = null;
            float rotation = 0f;
            float[] scale = null;
            string type = "";
            foreach (XmlAttribute attribute in node.Attributes)
            {
                switch (attribute.Name.ToLower())
                {
                    case "id":
                        id = int.Parse(attribute.Value);
                        break;
                    case "position":
                        position = FloatArrayUtils.ConvertStringToFloatArray(attribute.Value);
                        break;
                    case "rotation":
                        rotation = float.Parse(attribute.Value);
                        break;
                    case "scale":
                        scale = FloatArrayUtils.ConvertStringToFloatArray(attribute.Value);
                        break;
                    case "type":
                        type = attribute.Value;
                        break;
                }
            }

            IDeserializedObject @object = new ObjectDoodad(id, position, rotation, scale, type);
            GenericObjectNodeParser.Parse(node, @object);
            return @object;
        }

        internal ObjectDoodad(int id, float[] position, float rotation, float[] scale, string type)
            : base(id, position, rotation, scale, type, DoodadOwnerPlayer)
        {
        }
    }
}
